﻿using Basic.FormModel.DB;
using Basic.FormRemoteModel.PhysicalPage.Model;
using WeDonekRpc.Client;
using WeDonekRpc.Helper;
using WeDonekRpc.Helper.IdGenerator;
using WeDonekRpc.SqlSugar;

namespace Basic.FormDAL.Repository
{
    internal class PhysicalPageDAL : BasicDAL<DBPhysicalPage, long>, IPhysicalPageDAL
    {
        public PhysicalPageDAL ( IRepository<DBPhysicalPage> basicDAL ) : base(basicDAL, "physical.page")
        {
        }
        public long Add ( PhysicalPageSet add )
        {
            DBPhysicalPage page = add.ConvertMap<PhysicalPageSet, DBPhysicalPage>();
            page.Id = IdentityHelper.CreateId();
            this._BasicDAL.Insert(page);
            return page.Id;
        }
        public void SetPagePath ( long id, string path )
        {
            if ( !base._BasicDAL.Update(a => a.PagePath == path, a => a.Id == id) )
            {
                throw new ErrorException("form.physical.page.set.fail");
            }
        }
    }
}
